﻿using ByGeo.Geometries;
using ByGeo.IO;
using System;
using System.IO;
using By= Bouyei.GeoCore.Geometries;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            WKTIntersection();

            //EllipseArea();
        }

        static void WKTIntersection()
        {
            var wkt1 = File.ReadAllText("E:\\g1.wkt");
            var wkt2 = File.ReadAllText("E:\\g2.wkt");

            Geometry geo1 = new WKTReader().Read(wkt1);
            Geometry geo2 = new WKTReader().Read(wkt2);

            //验证要素是否有效,为空或者有自相交则无效
            if (geo1.IsValid == false)
            {
                return;
            }
            if (geo2.IsValid == false)
            {
                return;
            }

            //是否检查节点有效,如果存在自相交等则相交失败
           // ByGeo.Operation.Overlay.OverlayOp.NodingValidatorDisabled = true;
            var result = geo1.Intersection(geo2);

            var resultstr = new WKTWriter().Write(result);
            By.GeometryEllipse ellipse = new By.GeometryEllipse();
            double nArea = ellipse.Area(resultstr);

            Console.WriteLine(resultstr);
        }

        static void EllipseArea()
        {
            var g1 = "POLYGON ((105.66278148717595 26.268896196702144,105.65603151224457 26.270494874738745,105.6553345349609 26.27166525334883,105.65733907973481 26.273402525905908,105.6625862344672 26.271431379254807,105.66278148717595 26.268896196702144))";// File.ReadAllText("E:\\g1.wkt");

            Geometry geo1 = new WKTReader().Read(g1);
            double gArea = geo1.Area;//平面面积,所以必须是平面坐标系
           

            //wkt
            var text = geo1.AsText();

            By.GeometryEllipse ellipse = new By.GeometryEllipse();
            double nArea = ellipse.Area(text);
        }
    }
}
